package com.example.stock.service.impl;

import com.example.stock.excel.ExcelReaderUtil;
import com.example.stock.excel.FundUnits;
import com.example.stock.service.FundUnitsService;
import com.example.stock.util.DataUtil;
import jakarta.annotation.PostConstruct;
import lombok.extern.log4j.Log4j2;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
@Log4j2
public class FundUnitsServiceImpl implements FundUnitsService {

    private Map<String, List<FundUnits>> fundUnitsMap;

    @PostConstruct
    private void init() {
        List<FundUnits> fundUnitsList = DataUtil.getListData(FundUnits.class, ExcelReaderUtil.FILE_FUND_UNITS);
        fundUnitsMap = fundUnitsList.stream().collect(Collectors.groupingBy(FundUnits::getStock));
    }

    @Override
    public List<FundUnits> getFundUnits(String stock) {
        return fundUnitsMap.get(stock);
    }
}